using ConsoleApp2.input._1023;
using ConsoleApp2.input._1030.userservice;
using ConsoleApp2.input._1030.util;

namespace ConsoleApp2.input._1030;

public class UserServiceImpl : IUserService
{
    public void findAllUsers()
    {
        // JDBCUtil jdbcUtils = new JDBCUtil();
        // var conn = jdbcUtils.getConnection();
        // var sql = "select * from student";
        // var ps = conn.prepareStatement(sql);
        // var rs = ps.executeQuery();
        // while (rs.next())
        // {
        //     Console.WriteLine("id: " + rs.getInt("id") + ", username: " + rs.getString("username") + ", password: " +
        //                       rs.getString("password"));
        // }
    }

    public int findUser(string username)
    {
        JDBCUtil jdbcUtil = new JDBCUtil();
        var conn = jdbcUtil.getConnection();
        var sql = "select * from student where username = ?";
        // var ps = conn.prepareStatement(sql);
        // ps.setString(1, username);
        // var rs = ps.executeQuery();
        // if (rs.next())
        // {
        //     Console.WriteLine("id: " + rs.getInt("id") + ", username: " + rs.getString("username") + ", password: " +
        //                       rs.getString("password"));
        //     return 1; // 用户存在
        // }
        return 0; // 用户不存在
    }

    public int deleteUser(int userId)
    {
        // JDBCUtil jdbcUtil = new JDBCUtil();
        // var conn = jdbcUtil.getConnection();
        // string sql = "delete from student where id = ?";
        // PreparedStatement ps = conn.PrepareStatement();
        // ps.SetString(1, userId);
         return 0;
    }


public int updateUser(Student student)
    {
        // JDBCUtil jdbcUtil = new JDBCUtil();
        // var conn = jdbcUtil.getConnection();
        // string sql = "update student set name = ? , age = ?";
        // PreparedStatement ps = conn.PrepareStatement();
        // ps.SetString(1, student.StudentName);
        // ps.SetString(2, student.StudentAge);
         return 0;
    }

    public int insertUser(Student student)
    {
        // JDBCUtil jdbcUtil = new JDBCUtil();
        // var conn = jdbcUtil.getConnection();
        // string sql = "insert into student (name, age) values (?, ?)";
        // var preparedStatement = conn.PrepareStatement();
        // preparedStatement.SetString(1, student.StudentName);
        // preparedStatement.SetString(2, student.StudentAge);
         return 0;
    }
}